package com.mall.manager.allpeoplestatistics.service;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.collections.MapUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.web.util.WebUtils;

import com.mall.untils.DateUtil;
import com.mall.untils.Page;
/**
 * @全球数量统计
 * @author liugb
 * @date 2016 7 14
 */
@Service
public class AllPeopleStatisticsService {
	@Resource
    private JdbcTemplate jdbcTemplate;
	//日志信息
	private Logger logger = LoggerFactory.getLogger(AllPeopleStatisticsService.class);	
	/**
	 * @全球数量统计分页方法
	 * @param request
	 * @return
	 */
	public Page manager_allPeople_list(HttpServletRequest request) {
		Page page = null;
	    Map<String,Object> paraMap = WebUtils.getParametersStartingWith(request, "");
	    int pageNo = MapUtils.getIntValue(paraMap, "currentpageno");
		String update_time = MapUtils.getString(paraMap, "update_time");
		if(update_time == null || update_time.equals("null")){
			update_time = DateUtil.getTodayString();
		}
	    int pageSize = 10;
    	try {
 	        if (pageNo == 0){
 	        	pageNo = 1;
 	        }
 	        String sql = "select count(*) from db_processing.t_all_people_statistics where 1=1 and date_format(update_time,'%Y-%m-%d') = '" + update_time+"'";
 	        int total = jdbcTemplate.queryForObject(sql, Integer.class);
 	        int startIndex = Page.getStartOfPage(pageNo, pageSize);
 	        StringBuffer sb = new StringBuffer("select * from db_processing.t_all_people_statistics where 1=1 and date_format(update_time,'%Y-%m-%d') = '" + update_time+"'");
 	        sb.append(" order by id desc limit " + startIndex + "," + pageSize);
 	        List<Map<String, Object>>  queryForList = this.jdbcTemplate.queryForList(sb.toString());
 	        page = new Page(startIndex, total, pageSize, queryForList);
 	        return page;
 	    } catch (Exception e) {
 	        this.logger.info(e.toString());
 	        return null;
 	    }
	}
	

}
